﻿/*
 *  Author: Louis A. Leskoviansky
 *  Company: Artemis Solutions Group (http://www.artemis-solutions.com)
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace AjaxControlFramework
{
    public class UpdateRegionCallbackStrategy : ControlCallbackStrategy
    {
        //------// Constructors \\------------------------------------------\\
        public UpdateRegionCallbackStrategy(Control control)
			: base(control)
		{ }
		//------\\ Constructors //------------------------------------------//



        //------// Methods \\-----------------------------------------------\\
        protected override Dictionary<string, object> Update(CallbackStrategyArguments args)
        {
            // This override is nearly the same as its base class except the Control state 
            // is not loaded within this method. We don't want to load it in the Update method 
            // for the UpdateRegion since we're loading it immediately after the Control's
            // Init event. Leaving the loading of the Control state in this method would cause 
            // ControlState and ViewState to be loaded multiple times.

            // Create the context object to wrap the state and HTML of the IAjaxControl.
            AjaxControlContext newContext = new AjaxControlContext {
                State = args.state,
                Html = String.Empty,
                Control = LoadControl(args)
            };

            Control.AjaxContext = newContext;


            UpdateControl(newContext.Control, newContext);


            Dictionary<string, object> callbackResult = new Dictionary<string, object>();
            callbackResult.Add("State", newContext.State);
            callbackResult.Add("Html", newContext.Html);

            return callbackResult;
        }
		//------\\ Methods //-----------------------------------------------//
    }
}
